#include "StdAfx.h"
#include "PlayMode.h"


CPlayMode::CPlayMode(int lineCount): m_Intelligence(lineCount), m_GoBoardWithCommonProcess(lineCount)
{
	m_LineCount = lineCount;
	m_ToPlayFirst = HUMAN_PLAYER;
}


void CPlayMode::Init(void)
{
	m_Intelligence.Init();
	m_GoBoardWithCommonProcess.Init();
	SLocationOnGoBoard point;
	for (int i=0; i<4; i++) {
		point.x = 2 + i % 2 * 4;
		point.y = 2 + i / 2 * 4;
		m_GoBoardWithCommonProcess.SetRangzi(point);
	}
	m_GoBoardWithCommonProcess.SetPlayerToMove(WHITE_COLOR);
}


CPlayMode::~CPlayMode(void)
{
}


bool CPlayMode::Input(const SLocationOnGoBoard &input)
{
	if (m_GoBoardWithCommonProcess.m_GoBoard.GetPointStatus(BLACK_COLOR, input) == PIECE_ON_POINT ||
		m_GoBoardWithCommonProcess.m_GoBoard.GetPointStatus(WHITE_COLOR, input) == PIECE_ON_POINT) {
			return false;
	}
	if (m_GoBoardWithCommonProcess.Move(input)) {
		return true;
	} else {
		return false;
	}
}


bool CPlayMode::Ouput(void)
{
	SLocationOnGoBoard foolishMove;
	m_Intelligence.Think(m_GoBoardWithCommonProcess, &foolishMove);
	if (foolishMove.x == NONE_LOCATION && foolishMove.y == NONE_LOCATION) {
		return false;
	} else {
		m_GoBoardWithCommonProcess.Move(foolishMove);
		return true;
	}
}